package 多线程;

/**
 * @Author zhang lei
 * @Date 2021-12-23 15:22
 */
public class BankTest {
    public static void main(String[] args) {
        Account a = new Account();
        a.money = 500;
        a.name = "张";

        new Thread(new Bank(a, "你", 300)).start();
        new Thread(new Bank(a, "媳妇儿", 300)).start();

    }
}
class Bank implements Runnable{

    private Account account;

    private String name;

    private int getMoney;

    public Bank(Account a , String name, int money) {
        this.account = a;
        this.name = name;
        this.getMoney = money;
    }

    @Override
    public void run() {
        if(account.money < getMoney) {
            System.out.println(Thread.currentThread().getName()+"钱不够了");
            return;
        }
        account.money -= getMoney;
        System.out.println(Thread.currentThread().getName()+"取"+getMoney);
    }
}

class Account{
    int money;
    String name;
}
